﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
using System.Text;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class ODailyreportHighchartsPage : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "ODailyReport";
            }
        }
        #region 属性 (查询条件)
        protected int screeWidth
        {
            get
            {
                var x = GetRequestValue<int>("screeWidth", 800);
                return x - 80;
            }
        }

        protected string WorkDateForm
        {
            get
            {
                return GetRequestValue<string>("WorkDateForm", DateTime.Now.ToString("yyyy-MM-01"));

            }
        }

        protected string WorkDateTo
        {
            get
            {
                return GetRequestValue<string>("WorkDateTo", DateTime.Now.ToString("yyyy-MM-dd"));
            }
        }

        protected string ReportType
        {
            get
            {
                return GetRequestValue<string>("ReportType", "1");
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = 0;
            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
            Response.AddHeader("pragma", "no-cache");
            Response.CacheControl = "no-cache";


            switch (ReportType)
            {
                case "1":
                    DataBind1();
                    break;
                case "2":
                    DataBind2();
                    break;
                case "3":
                    DataBind3();
                    break;
                case "4":
                    DataBind4();
                    break;
                case "5":
                    DataBind5();
                    break;
                case "6":
                    DataBind6();
                    break;
            }
            DataBind();
        }


        protected int containerWidth = 800;
        protected int containerHeight = 400;
        #region 报表1.每个项目中每台机器的直接工时平均值
        protected void DataBind1()
        {
            double tasktimes = 0;
            foreach (DataRow dr in report1dts[0].Rows)
            {
                tasktimes = tasktimes + Convert.ToDouble(dr["mactasktime"]);
            }
            report1subtitle = string.Format("从{0}到{1}总直接工时为{2}小时", WorkDateForm, WorkDateTo, tasktimes);
            rpMachineTaskTimeChart.DataSource = report1dts[0];
            rpMachineTaskTimeChart.DataBind();
            rpMachineTaskTimeChart2.DataSource = report1dts[1];
            rpMachineTaskTimeChart2.DataBind();
        }


        protected string report1subtitle="";
        private DataTableCollection _report1dts = null;
        private DataTableCollection report1dts
        {
            get
            {
                if (_report1dts == null)
                    _report1dts = ODailyController.GetMachineTaskTimeChart(WorkDateForm, WorkDateTo);
                return _report1dts;
            }
        }
        /// <summary>
        /// 获取报表1 主表的X轴
        /// </summary>
        /// <returns></returns>
        protected string GetReport1JSCategories()
        {
            
            DataTable dtcl = report1dts[1];
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            List<string> colNames = new List<string>();

            foreach (DataRow dc in dtcl.Rows)
            {
                sb.AppendFormat("'{0}',", dc[0]);
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            int lastpos = filedstr.LastIndexOf(",");
            filedstr = filedstr.Remove(lastpos, 1);
            return filedstr;
        }
        /// <summary>
        /// 获取报表1 表信息
        /// </summary>
        /// <returns></returns>
        protected string GetReport1JSData()
        {
            /*
             data = [{
		        y: 45.78,
		        color: colors[0],
		        drilldown: {
		            name: '55NSL(13)各项目单台机器平均工时',
		            categories: ['55NSL120101(10)', '55NSL120102(3)'],
		            data: [45, 46],
		            color: colors[0]
		        }
		    }, {
		        y: 59.69,
		        color: colors[1],
		        drilldown: {
		            name: '65NSL(29)各项目单台机器平均工时',
		            categories: ['65NS120101(10)', '65NS120102(19)'],
		            data: [45, 46],
		            color: colors[1]
		        }
		    }];
             */
            
            DataTable dtmain = report1dts[1];
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");
            int rowindex = 1;
            foreach (DataRow dr in dtmain.Rows)
            {
                sb.AppendFormat("{{y: {0},color: colors[{1}],",Convert.ToDecimal(dr["averagetasktime"]).ToString("f2"),rowindex);

                sb.AppendLine(GetReport1Drilldown(rowindex, dr["MachineType"].ToString()));

                sb.AppendLine("}");

                if (rowindex != dtmain.Rows.Count)
                {
                    sb.AppendLine(",");
                }

                rowindex++;
            }
            sb.AppendLine("];");
            return sb.ToString();
        }

        private string GetReport1Drilldown(int rowindex, string MachineType)
        {
            /*
              drilldown: {
		            name: '55NSL(13)各项目单台机器平均工时',
		            categories: ['55NSL120101(10)', '55NSL120102(3)'],
		            data: [45, 46],
		            color: colors[0]
		        }
             */
            
            DataTable dtdetail = report1dts[0];
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("drilldown: {");
            sb.AppendFormat("name: '{0}各项目单台机器平均工时',", MachineType);

            DataRow[] dtdetailslect = dtdetail.Select(" MachineType='" + MachineType + "'");
            string categories = "categories:[";
            string data = "data:[";
            int r = 1;
            foreach (DataRow dr in dtdetailslect)
            {
                categories += "'" +  dr["SerialNumberNum"].ToString() + "'";
                data +=  Convert.ToDecimal( dr["TaskTime"]).ToString("f2");
                if (r != dtdetailslect.Count())
                {
                    categories += ",";
                    data += ",";
                }
                r++;
            }
            categories += "],";
            data += "],";

            sb.AppendLine(categories);
            sb.AppendLine(data);
            sb.AppendFormat("color:colors[{0}]",rowindex);
            sb.AppendLine("}");
            return sb.ToString();
        }
        #endregion

        #region 报表2.每月直接间接工时

        protected void DataBind2()
        {

            this.rp2_1.DataSource = report2dts[0];
            this.rp2_1.DataBind();
            //

            foreach (DataRow dr in report2dts[1].Rows)
            {
                totaltasktime += Convert.ToDecimal(dr["TaskTime"]);
            }
            this.rp2_2.DataSource = report2dts[1];
            this.rp2_2.DataBind();

        }
        protected decimal totaltasktime = 0m;
        protected object GetPer2(object 被除数, object 除数)
        {
            decimal x被除数 = Convert.ToDecimal(被除数);
            decimal x除数 = Convert.ToDecimal(除数);
            if (x除数 == 0)
                return 0;
            return ((x被除数 / (x除数 + x被除数)) * 100).ToString("f1") + "%";
        }
        protected object GetPer2_1(object 被除数)
        {
            decimal x被除数 = Convert.ToDecimal(被除数);
            if (totaltasktime == 0)
                return 0;
            return ((x被除数 / totaltasktime) * 100).ToString("f1") + "%";
        }

        private DataTableCollection _report2dts = null;
        private DataTableCollection report2dts
        {
            get
            {
                if (_report2dts == null)
                    _report2dts = ODailyController.GetMachineTaskTime2(WorkDateForm, WorkDateTo);
                return _report2dts;
            }
        }
        /// <summary>
        /// 获取报表2 主表的X轴
        /// </summary>
        /// <returns></returns>
        protected string GetReport2JSCategories()
        {
            DataTable dtcl = report2dts[0];
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            int rowindex = 1;
            foreach (DataRow dr in dtcl.Rows)
            {
                sb.AppendFormat("'{0}'", dr[0]);
                if (rowindex != dtcl.Rows.Count)
                {
                    sb.AppendFormat(",");
                }
                rowindex++;
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            return filedstr;
        }

        protected string GetReport2JSSeries()
        {
            /*
             [{
                    name: 'John',
                    data: [5, 3, 4, 7, 2]
                }, {
                    name: 'Jane',
                    data: [2, 2, 3, 2, 1]
                }, {
                    name: 'Joe',
                    data: [3, 4, 4, 2, 5]
                }]
             */
            DataTable dtmain = report2dts[0];
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");

            string str直接 = "{name: '直接',data:[";
            string str间接 = "{name: '间接',data:[";

            int rowindex = 1;
            foreach (DataRow dr in dtmain.Rows)
            {
                str直接 += Convert.ToDecimal(dr["直接"]).ToString("f2");
                str间接 += Convert.ToDecimal(dr["间接"]).ToString("f2");
                if (rowindex != dtmain.Rows.Count)
                {
                    str直接 += ",";
                    str间接 += ",";
                }
                rowindex++;
            }
            str直接 += "]},";
            str间接 += "]}";


            sb.AppendLine(str直接);
            sb.AppendLine(str间接);
            sb.AppendLine("]");
            return sb.ToString();
        }
        #endregion

        #region 报表3.每个项目中每台机器平均工时
        protected void DataBind3()
        {
            rpMachineTaskTimeChart3.DataSource = report3dts;
            rpMachineTaskTimeChart3.DataBind();

            double tasktimes = 0;
            foreach (DataRow dr in report3dts.Rows)
            {
                tasktimes = tasktimes + Convert.ToDouble(dr["mactasktime"]);
            }

            report3subtitle = string.Format("从{0}到{1}总工时为{2}小时", WorkDateForm, WorkDateTo, tasktimes);
         
        }


        protected string report3subtitle = "";
        private DataTable _report3dts = null;
        private DataTable report3dts
        {
            get
            {
                if (_report3dts == null)
                    _report3dts = ODailyController.GetMachineTaskTime3(WorkDateForm, WorkDateTo);
                return _report3dts;
            }
        }
        List<string> Report3colNames = new List<string>();
        /// <summary>
        /// 获取报表1 主表的X轴
        /// </summary>
        /// <returns></returns>
        protected string GetReport3JSCategories()
        {

            DataTable dtcl = report3dts;
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            foreach (DataRow dr in dtcl.Rows)
            {
                string MachineType = dr["MachineType"].ToString();
                if (!Report3colNames.Contains(MachineType))
                {
                    Report3colNames.Add(MachineType);
                    sb.AppendFormat("'{0}',", MachineType);
                }
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            int lastpos = filedstr.LastIndexOf(",");
            filedstr = filedstr.Remove(lastpos, 1);
            return filedstr;
        }
        /// <summary>
        /// 获取报表1 表信息
        /// </summary>
        /// <returns></returns>
        protected string GetReport3JSData()
        {
            /*
             data = [{
		        y: 45.78,
		        color: colors[0],
		        drilldown: {
		            name: '55NSL(13)各项目单台机器平均工时',
		            categories: ['55NSL120101(10)', '55NSL120102(3)'],
		            data: [45, 46],
		            color: colors[0]
		        }
		    }, {
		        y: 59.69,
		        color: colors[1],
		        drilldown: {
		            name: '65NSL(29)各项目单台机器平均工时',
		            categories: ['65NS120101(10)', '65NS120102(19)'],
		            data: [45, 46],
		            color: colors[1]
		        }
		    }];
             */

          
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");
            int rowindex = 1;
            foreach (string colName in Report3colNames)
            {
                sb.AppendFormat("{{y: {0},color: colors[{1}],", GetReport3MacTypeAlltasktime(colName).ToString("f2"), rowindex);

                sb.AppendLine(GetReport3Drilldown(rowindex, colName));

                sb.AppendLine("}");

                if (rowindex != Report3colNames.Count)
                {
                    sb.AppendLine(",");
                }

                rowindex++;
            }
            sb.AppendLine("];");
            return sb.ToString();
        }

        private decimal GetReport3MacTypeAlltasktime(string MachineType)
        {
            DataTable dtmain = report3dts;
            DataRow[] dtselect=  dtmain.Select(" MachineType='" + MachineType + "'");
            decimal result=0m;
            int pNum = 0;
            foreach(DataRow  dr in dtselect)
            {
                result += Convert.ToDecimal(dr["alltasktime"]);
                pNum++;
            }
            return pNum==0?0: result / pNum;
        }

        private string GetReport3Drilldown(int rowindex, string MachineType)
        {
            /*
              drilldown: {
		            name: '55NSL(13)各项目单台机器平均工时',
		            categories: ['55NSL120101(10)', '55NSL120102(3)'],
		            data: [45, 46],
		            color: colors[0]
		        }
             */

            DataTable dtdetail = report3dts;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("drilldown: {");
            sb.AppendFormat("name: '{0}各项目单台机器负担平均工时',", MachineType);

            DataRow[] dtdetailslect = dtdetail.Select(" MachineType='" + MachineType + "'");
            string categories = "categories:[";
            string data = "data:[";
            int r = 1;
            foreach (DataRow dr in dtdetailslect)
            {
                categories += "'" + dr["SerialNumberNum"].ToString() + "'";
                data += Convert.ToDecimal(dr["alltasktime"]).ToString("f2");
                if (r != dtdetailslect.Count())
                {
                    categories += ",";
                    data += ",";
                }
                r++;
            }
            categories += "],";
            data += "],";

            sb.AppendLine(categories);
            sb.AppendLine(data);
            sb.AppendFormat("color:colors[{0}]", rowindex);
            sb.AppendLine("}");
            return sb.ToString();
        }
        #endregion

        #region 报表4.按工位统计工时
        protected void DataBind4()
        {
            containerWidth = 800;
            containerHeight = 1200;
            //this.rp2_1.DataSource = report2dts[0];
            //this.rp2_1.DataBind();
            ////

            //foreach (DataRow dr in report2dts[1].Rows)
            //{
            //    totaltasktime += Convert.ToDecimal(dr["TaskTime"]);
            //}
            //this.rp2_2.DataSource = report2dts[1];
            //this.rp2_2.DataBind();

        }

        List<string> Report4colNames = new List<string>();
        private DataTable _report4dts = null;
        private DataTable report4dts
        {
            get
            {
                if (_report4dts == null)
                    _report4dts = ODailyController.GetMachineTaskTime4(WorkDateForm, WorkDateTo);
                return _report4dts;
            }
        }
        /// <summary>
        /// 获取报表2 主表的X轴
        /// </summary>
        /// <returns></returns>
        protected string GetReport4JSCategories()
        {
            DataTable dtcl = report4dts;
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            int rowindex = 1;
            foreach (DataRow dr in dtcl.Rows)
            {
                string GongWei=dr["GongWei"].ToString();
                if (!Report4colNames.Contains(GongWei))
                {
                    sb.AppendFormat("'{0}'", GongWei);
                    Report4colNames.Add(GongWei);
                    if (rowindex != dtcl.Rows.Count)
                    {
                        sb.AppendFormat(",");
                    }
                }               
                
                rowindex++;
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            return filedstr;
        }

        protected string GetReport4JSSeries()
        {
            /*
             [{
                    name: 'John',
                    data: [5, 3, 4, 7, 2]
                }, {
                    name: 'Jane',
                    data: [2, 2, 3, 2, 1]
                }, {
                    name: 'Joe',
                    data: [3, 4, 4, 2, 5]
                }]
             */
            DataTable dtmain = report4dts;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");


            List<string> listMachineType = new List<string>();
            foreach (DataRow dr in dtmain.Rows)
            {
                string MachineType = dr["MachineType"].ToString();
                if (!listMachineType.Contains(MachineType))
                {
                    listMachineType.Add(MachineType);
                }
            }
            int rowNum = 1;
            foreach (string MachineType in listMachineType)
            {
                string str直接 = "{name: '" + MachineType + "',data:[";
                int rowindex = 1;
                foreach (string colName in Report4colNames)
                {
                    DataRow[] drs=  dtmain.Select(string.Format(" MachineType='{0}' and GongWei='{1}'", MachineType, colName));

                    string TaskTime = drs.Count()>0? Convert.ToDecimal(drs[0]["TaskTime"]).ToString("f2"):"0";
                    str直接 += TaskTime;
                    if (rowindex != Report4colNames.Count)
                    {
                        str直接 += ",";
                    }
                    rowindex++;
                }
                str直接 += "]}";

                if (rowNum != listMachineType.Count)
                {
                    str直接 += ",";
                }
                sb.AppendLine(str直接);
                rowNum++;
            }            
            sb.AppendLine("]");
            return sb.ToString();
        }
        #endregion

        #region 报表5.按项目统计直接工时对比
        protected void DataBind5()
        {
            DataTable dt2 = report5dts.Copy();
            dt2.Columns[0].ColumnName = "项目";
            GridView5.DataSource = dt2;
            GridView5.DataBind();
        }
       
        private DataTable _report5dts = null;
        private DataTable report5dts
        {
            get
            {
                if (_report5dts == null)
                    _report5dts = ODailyController.GetMachineTaskTime5(WorkDateForm, WorkDateTo);
                return _report5dts;
            }
        }
        /// <summary>
        /// 获取报表5 主表的X轴
        /// </summary>
        /// <returns></returns>
        protected string GetReport5JSCategories()
        {
            //按工作内容
            DataTable dtcl = report5dts;
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            int cNum = 1;
            foreach (DataColumn dc in dtcl.Columns)
            {
                if (dc.ColumnName == "SerialNumber")
                    continue;
                sb.AppendFormat("'{0}'", dc.ColumnName);
                if (cNum != dtcl.Columns.Count - 1)
                {
                    sb.Append(",");
                }
                cNum++;
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            return filedstr;
            //按项目
            //DataTable dtcl = report5dts;
            //StringBuilder sb = new StringBuilder();

            //sb.Append("[");
            //int cNum = 1;
            //foreach (DataRow dr in dtcl.Rows)
            //{
            //    sb.AppendFormat("'{0}'", dr["SerialNumber"]);
            //    if (cNum != dtcl.Rows.Count)
            //    {
            //        sb.Append(",");
            //    }
            //    cNum++;
            //}
            //sb.Append("]");
            //string filedstr = sb.ToString();
            //return filedstr;
            
        }

        protected string GetReport5JSSeries()
        {
            /*
             [{
                    name: 'John',
                    data: [5, 3, 4, 7, 2]
                }, {
                    name: 'Jane',
                    data: [2, 2, 3, 2, 1]
                }, {
                    name: 'Joe',
                    data: [3, 4, 4, 2, 5]
                }]
             */
            /*
            [{
                   name: 'John',
                   data: [5, 3, 4, 7, 2]
               }, {
                   name: 'Jane',
                   data: [2, 2, 3, 2, 1]
               }, {
                   name: 'Joe',
                   data: [3, 4, 4, 2, 5]
               }]
            */

            DataTable dtmain = report5dts;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");
            #region 按项目分
                 /*    
            int cNum = 1;
            foreach (DataColumn dc in dtmain.Columns)
            {
                if (dc.ColumnName == "SerialNumber")
                    continue;

                int rowNum = 1;
                string str直接 = "{name: '" + dc.ColumnName + "',data:[";
                foreach (DataRow dr in dtmain.Rows)
                {
                    str直接 += dr[dc.ColumnName];
                    if (rowNum != dtmain.Rows.Count)
                    {
                        str直接 += ",";
                    }
                    rowNum++;
                }
                str直接 += "]}";
                if (cNum != dtmain.Columns.Count - 1)
                {
                    str直接 += ",";
                }
                sb.AppendLine(str直接);
                cNum++;
            }
            */
             
            #endregion
            
            #region 按工作内容分
            
            int rowNum = 1;

            foreach (DataRow dr in dtmain.Rows)
            {
                string str直接 = "{name: '" + dr["SerialNumber"] + "',data:[";
                int cNum = 1;
                foreach (DataColumn dc in dtmain.Columns)
                {
                    if (dc.ColumnName == "SerialNumber")
                        continue;
                    str直接 += dr[dc.ColumnName];
                    if (cNum != dtmain.Columns.Count - 1)
                    {
                        str直接 += ",";
                    }
                    cNum++;
                }
                str直接 += "]}";

                if (rowNum != dtmain.Rows.Count)
                {
                    str直接 += ",";
                }

                sb.AppendLine(str直接);
                rowNum++;
            }
           
            #endregion


            sb.AppendLine("]");
            return sb.ToString();
        }
        #endregion

        #region 报表6.按月统计直接工时对比
        protected void DataBind6()
        {
            DataTable dt2 = report6dts.Copy();
            dt2.Columns[0].ColumnName = "工作内容";
            GridView6.DataSource = dt2;
            GridView6.DataBind();
        }

        private DataTable _report6dts = null;
        private DataTable report6dts
        {
            get
            {
                if (_report6dts == null)
                    _report6dts = ODailyController.GetMachineTaskTime6(WorkDateForm, WorkDateTo);
                return _report6dts;
            }
        }
        /// <summary>
        /// 获取报表6 主表的X轴
        /// </summary>
        /// <returns></returns>
        protected string GetReport6JSCategories()
        {
            //按工作内容
            DataTable dtcl = report6dts;
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            int cNum = 1;
            foreach (DataColumn dc in dtcl.Columns)
            {
                if (dc.ColumnName == "jobtitle")
                    continue;
                sb.AppendFormat("'{0}'", dc.ColumnName);
                if (cNum != dtcl.Columns.Count - 1)
                {
                    sb.Append(",");
                }
                cNum++;
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            return filedstr;
            //按项目
            //DataTable dtcl = report5dts;
            //StringBuilder sb = new StringBuilder();

            //sb.Append("[");
            //int cNum = 1;
            //foreach (DataRow dr in dtcl.Rows)
            //{
            //    sb.AppendFormat("'{0}'", dr["SerialNumber"]);
            //    if (cNum != dtcl.Rows.Count)
            //    {
            //        sb.Append(",");
            //    }
            //    cNum++;
            //}
            //sb.Append("]");
            //string filedstr = sb.ToString();
            //return filedstr;

        }

        protected string GetReport6JSSeries()
        {
            /*
             [{
                    name: 'John',
                    data: [5, 3, 4, 7, 2]
                }, {
                    name: 'Jane',
                    data: [2, 2, 3, 2, 1]
                }, {
                    name: 'Joe',
                    data: [3, 4, 4, 2, 5]
                }]
             */
            /*
            [{
                   name: 'John',
                   data: [5, 3, 4, 7, 2]
               }, {
                   name: 'Jane',
                   data: [2, 2, 3, 2, 1]
               }, {
                   name: 'Joe',
                   data: [3, 4, 4, 2, 5]
               }]
            */

            DataTable dtmain = report6dts;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");
            #region 按项目分
            /*    
            int cNum = 1;
            foreach (DataColumn dc in dtmain.Columns)
            {
                if (dc.ColumnName == "SerialNumber")
                    continue;

                int rowNum = 1;
                string str直接 = "{name: '" + dc.ColumnName + "',data:[";
                foreach (DataRow dr in dtmain.Rows)
                {
                    str直接 += dr[dc.ColumnName];
                    if (rowNum != dtmain.Rows.Count)
                    {
                        str直接 += ",";
                    }
                    rowNum++;
                }
                str直接 += "]}";
                if (cNum != dtmain.Columns.Count - 1)
                {
                    str直接 += ",";
                }
                sb.AppendLine(str直接);
                cNum++;
            }
            */

            #endregion

            #region 按工作内容分

            int rowNum = 1;

            foreach (DataRow dr in dtmain.Rows)
            {
                string str直接 = "{name: '" + dr["jobtitle"] + "',data:[";
                int cNum = 1;
                foreach (DataColumn dc in dtmain.Columns)
                {
                    if (dc.ColumnName == "jobtitle")
                        continue;
                    str直接 += dr[dc.ColumnName];
                    if (cNum != dtmain.Columns.Count - 1)
                    {
                        str直接 += ",";
                    }
                    cNum++;
                }
                str直接 += "]}";

                if (rowNum != dtmain.Rows.Count)
                {
                    str直接 += ",";
                }

                sb.AppendLine(str直接);
                rowNum++;
            }

            #endregion


            sb.AppendLine("]");
            return sb.ToString();
        }
        #endregion
        /*
       
        protected decimal totaltasktime = 0m;
        protected object GetPer2(object 被除数, object 除数)
        {
            decimal x被除数 = Convert.ToDecimal(被除数);
            decimal x除数 = Convert.ToDecimal(除数);
            if (x除数 == 0)
                return 0;
            return ((x被除数 / (x除数 + x被除数)) * 100).ToString("f1") + "%";
        }
        protected object GetPer2_1(object 被除数)
        {
            decimal x被除数 = Convert.ToDecimal(被除数);
            if (totaltasktime == 0)
                return 0;
            return ((x被除数 / totaltasktime) * 100).ToString("f1") + "%";
        }

        protected void DataBind3()
        {
            DataTable dt = ODailyController.GetMachineTaskTime3(WorkDateForm, WorkDateTo);
            rpMachineTaskTimeChart3.DataSource = dt;
            rpMachineTaskTimeChart3.DataBind();
            MachineTaskTimeChart3.DataSource = dt;
            MachineTaskTimeChart3.Series["Series1"].XValueMember = "SerialNumberNum";
            MachineTaskTimeChart3.Series["Series1"].YValueMembers = "alltasktime";
            MachineTaskTimeChart3.DataBind();

            MachineTaskTimeChart3.Series["Series1"]["DrawingStyle"] = "Cylinder";
            MachineTaskTimeChart3.Series["Series1"]["PointWidth"] = "0.4";

            double tasktimes = 0;
            foreach (DataRow dr in dt.Rows)
            {
                tasktimes = tasktimes + Convert.ToDouble(dr["mactasktime"]);
            }

            MachineTaskTimeChart3.Titles["TaskTimeTitle"].Text = string.Format(MachineTaskTimeChart3.Titles["TaskTimeTitle"].Text, WorkDateForm, WorkDateTo, tasktimes);
            MachineTaskTimeChart3.Width = screeWidth;
        }
        protected void DataBind4()
        {
            DataTable dt = ODailyController.GetMachineTaskTime4(WorkDateForm, WorkDateTo);
            rpMachineTaskTimeChart4.DataSource = dt;
            rpMachineTaskTimeChart4.DataBind();
            MachineTaskTimeChart4.DataSource = dt;
            MachineTaskTimeChart4.Series["Series1"].XValueMember = "GongWei";
            MachineTaskTimeChart4.Series["Series1"].YValueMembers = "TaskTime";
            MachineTaskTimeChart4.DataBind();
            MachineTaskTimeChart4.Width = 600;
            //double tasktimes = 0;
            //foreach (DataRow dr in dt.Rows)
            //{
            //    tasktimes = tasktimes + Convert.ToDouble(dr["TaskTime"]);
            //}

            //MachineTaskTimeChart.Titles["TaskTimeTitle"].Text = string.Format("从{0}到{1}总直接工时为{2}分钟", WorkDateForm, WorkDateTo, tasktimes);
        }
        protected void DataBind5()
        {
            Chart5.Series.Clear();
            DataTable dt = ODailyController.GetMachineTaskTime5(WorkDateForm, WorkDateTo);

            foreach (DataColumn dc in dt.Columns)
            {
                if (dc.ColumnName == "SerialNumber")
                    continue;
                Series ser = new Series(dc.ColumnName) { ChartType = SeriesChartType.StackedBar100, BorderWidth = 3, MarkerStyle = MarkerStyle.Square, IsVisibleInLegend = true, IsValueShownAsLabel = true, LabelFormat = "{f1}%" };
                ser.XValueMember = "SerialNumber";
                ser.YValueMembers = dc.ColumnName;
                ser.IsValueShownAsLabel = true;
                ser["LabelStyle"] = "Center";
                Chart5.Series.Add(ser);
            }
            //Series ser1 = new Series("80NS002") { ChartType = SeriesChartType.Line, BorderWidth = 3, MarkerStyle = MarkerStyle.Square, IsVisibleInLegend = true, IsValueShownAsLabel = true };
            //ser1.XValueMember = "JobTitle";
            //ser1.YValueMembers = "80NS002";
            //Chart1.Series.Add(ser1);

            Chart5.DataSource = dt;
            Chart5.DataBind();
            Chart5.Width = screeWidth;

            DataTable dt2 = dt.Copy();
            dt2.Columns[0].ColumnName = "项目";
            GridView5.DataSource = dt2;
            GridView5.DataBind();

            //GridView5.Columns[0].HeaderText = "项目";
        }
        protected void DataBind6()
        {
            Chart6.Series.Clear();
            DataTable dt = ODailyController.GetMachineTaskTime6(WorkDateForm, WorkDateTo);

            foreach (DataColumn dc in dt.Columns)
            {
                if (dc.ColumnName == "jobtitle")
                    continue;

                Series ser = new Series(dc.ColumnName) { ChartType = SeriesChartType.StackedBar100, BorderWidth = 3, MarkerStyle = MarkerStyle.Square, IsVisibleInLegend = true, IsValueShownAsLabel = true, LabelFormat = "{f1}%" };
                ser.XValueMember = "jobtitle";
                ser.YValueMembers = dc.ColumnName;
                ser.IsValueShownAsLabel = true;
                ser["LabelStyle"] = "Center";
                Chart6.Series.Add(ser);

            }
            //Series ser1 = new Series("80NS002") { ChartType = SeriesChartType.Line, BorderWidth = 3, MarkerStyle = MarkerStyle.Square, IsVisibleInLegend = true, IsValueShownAsLabel = true };
            //ser1.XValueMember = "JobTitle";
            //ser1.YValueMembers = "80NS002";
            //Chart1.Series.Add(ser1);

            Chart6.DataSource = dt;
            Chart6.DataBind();
            Chart6.Width = screeWidth;

            DataTable dt2 = dt.Copy();
            dt2.Columns[0].ColumnName = "工作内容";
            GridView6.DataSource = dt2;
            GridView6.DataBind();
        }
         */
    }
}